package com.shengzai

import com.mysql.jdbc.Driver

import java.sql.{Date, DriverManager, ResultSet, Statement}

object Code06MySQLJdbc {
  def main(args: Array[String]): Unit = {
    DriverManager.registerDriver(new Driver())

    val conn = DriverManager.getConnection("jdbc:mysql://192.168.146.136:3306/bigdata22?useSSL=false", "root", "123456")
    val statement: Statement = conn.createStatement()
    val sql: String =
      """
        |select
        |*
        |from
        |car_info
        |""".stripMargin

    val resultSet: ResultSet = statement.executeQuery(sql)

    while (resultSet.next()) {
      val car_id: String = resultSet.getString(1)
      val car_no: String = resultSet.getString(2)
      val pass_time: String = resultSet.getString(3)
      println(s"$car_id\t$car_no\t$pass_time")
    }

    statement.close()
    conn.close()

  }
}
